<?php
/**
 * @filename StaffController.php 
 * @encoding UTF-8 
 * @author KangShuAn
 * @datetime 2015-2-3 11:34:05
 * @version 1.0
 * @Description 排班
 */
class StaffController extends AdminController
{
    
    private $pagesize = 15;
    public function actionNetwork()
    {
        $p = $this->get('p', 1);
        $open_staff = $this->get('open_staff');
        $criteria = new CDbCriteria();
        
        if ($open_staff) 
        {
            $criteria->addColumnCondition(array('open_staff' => $open_staff));
        }
        
        $criteria->addColumnCondition(array('level' => NetWork::NETWORK_LEVEL_FOUR));
        $count = NetWork::model()->count($criteria);

        $criteria->limit = $this->pagesize;
        $criteria->offset = ($p - 1) * $this->pagesize;
        $criteria->order = 'open_staff desc,network_id desc';
        $data = NetWork::model()->findAll($criteria);
        $page = new Page($count, $this->pagesize);   
        $this->smarty->assign('page', $page->style1());
        $this->smarty->assign('list', $data);
        $this->smarty->assign('banklist', NetworkBank::model()->getKv());
        $this->smarty->display("staff/network.tpl");
    }
    /**
     * 开启关闭
     */
    public function actionOpen()
    {
        $network_id = (int)$this->get('network_id');
        $open_staff = (int)$this->get('open_staff');
        $network = new NetWork();
        $res = $network->updateAll(array('open_staff'=> $open_staff),'network_id='.$network_id);
        if ($res) {
            $this->_ajax(array('status' => 1));
        } else {
            $this->_ajax(array('status' => 0));
        }
    }
    /**
     * 网点下员工列表
     */
    public function actionlist()
    {
        $network_id = $this->get('network_id');
        
        $p = $this->get('p', 1);
        $criteria = new CDbCriteria();

        $criteria->addColumnCondition(array('status' =>1));
        $count = NetworkStaff::model()->count($criteria);

        $criteria->limit = $this->pagesize;
        $criteria->offset = ($p - 1) * $this->pagesize;
        $criteria->order = 'create_time desc';
        $data = NetworkStaff::model()->findAll($criteria);
        $page = new Page($count, $this->pagesize);   
        $this->smarty->assign('page', $page->style1());
        $this->smarty->assign('list', $data);
        $this->smarty->display("staff/list.tpl");
    }
    /**
     * 添加员工
     */
    public function actionAdd()
    {
        $network_id = $this->get('network_id');
        $this->smarty->display('staff/add.tpl');
    }
    public function actionDoadd()
    {
        $staff = new NetworkStaff();
        $staff->network_id = (int)$this->post('network_id');
        $staff->station = $this->post('station');
        $staff->staff_name = $this->post('staff_name');
        $staff->staff_identifier = $this->post('staff_identifier');
        $staff->photo = $this->post('photo');
        $staff->temporary = $this->post('temporary');
        $staff->shift = $this->post('shift');
        $staff->new_station = $this->post('new_station');
        $staff->shift_time = $this->post('shift_time');
        $staff->update_time = time();
        $staff->save($data);
        if ($res) {
            $this->jump('添加成功', '/webadmin/staff/list');
        } else {
            $this->jump('添加失败');
        }
    }
    /**
     * 编辑
     */
    public function actionEdit()
    {
        
    }
    /**
     * 删除
     */
    public function actionDel()
    {
        $staff_id = (int)$this->get('staff_id');
        $staff = new NetworkStaff();
        $res = $staff->updateByPk($staff_id, array('status' => 0));
        if($res){
            $this->_ajax(array('status' => 1));
        }else{
            $this->_ajax(array('status' => 0));
        }
    }
    /**
     * 安排
     */
    public function actionSchedule()
    {
        $this->smarty->display('staff/schedule.tpl');
    }
}
